﻿#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using Unity.Collections;
using UnityEngine;
/// <summary>
/// 语言包设定XML
/// </summary>
[XmlRoot("ESF_Xml_LanguageSetting")]
public class ESF_Xml_LanguageSetting : AbsESF_Xml
{
    /// <summary>
    /// 语言包脚本目录
    /// </summary>
    [XmlElement("语言包脚本目录")]
    [ESF_GUIOperation()]
    [ESF_PathSelect(enESF_PathSelectCatalogClassify.InternalAssets, enESF_PathSelectAssetClassify.Folder)]
    public string languageHelperScriptFolder;

    /// <summary>
    /// 语言包脚本类名
    /// </summary>
    [XmlElement("语言包脚本类名")]
    [ESF_GUIBrower()]
    [ReadOnly()]
    public string languageHelperScriptClassName;

    /// <summary>
    /// 缺省替换语言
    /// </summary>
    [XmlElement("缺省替换语言")]
    public enESF_AllLanguageClassify defaultAlternateLanguage;

    /// <summary>
    /// 默认语言
    /// </summary>
    [XmlElement("默认语言")]
    public enESF_AllLanguageClassify defaultLanguage;

    /// <summary>
    /// 语言包设置
    /// </summary>
    [XmlElement("语言包设置")]
    [ESF_GUIOperation()]
    [ESF_GUISeparator()]
    [ESF_ArrayMaxLength(typeof(enESF_AllLanguageClassify))]
    public ESF_Xml_LanguageSetting_Item[] items;

    /// <summary>
    /// 支持语言包
    /// </summary>
    [XmlElement("支持语言包")]
    [ReadOnly]
    [HideInInspector]
    [ESF_ArrayMaxLength(typeof(enESF_AllLanguageClassify))]
    public ESF_Xml_LanguageSetting_Item[] supportLangs;

    /// <summary>
    /// 不支持语言包
    /// </summary>
    [XmlElement("不支持语言包")]
    [ReadOnly]
    [HideInInspector]
    [ESF_ArrayMaxLength(typeof(enESF_AllLanguageClassify))]
    public ESF_Xml_LanguageSetting_Item[] unSupportLangs;

    protected override void OnResolve()
    {
        languageHelperScriptClassName = "ESF_LanguageHelper";
        List<ESF_Xml_LanguageSetting_Item> sup = new List<ESF_Xml_LanguageSetting_Item>();
        List<ESF_Xml_LanguageSetting_Item> unSup = new List<ESF_Xml_LanguageSetting_Item>();
        if (items != null)
        {
            foreach (var key in items)
            {
                if (key.isSupport)
                {
                    sup.Add(key);
                }
                else
                {
                    unSup.Add(key);
                }
            }
        }
        supportLangs = sup.ToArray();
        unSupportLangs = unSup.ToArray();
    }
}

/// <summary>
/// 语言包设定XML子项
/// </summary>
[XmlRoot("ESF_Xml_LanguageSetting_Item")]
public class ESF_Xml_LanguageSetting_Item
{
    /// <summary>
    /// 语言类别
    /// </summary>
    [XmlElement("语言类别")]
    [ESF_NoDuplicateValue()]
    public enESF_AllLanguageClassify classify;
    /// <summary>
    /// 是否支持
    /// </summary>
    [XmlElement("是否支持")]
    public bool isSupport;

    /// <summary>
    /// 是否默认语言
    /// </summary>
    public bool isDefalut { get { return classify == ESF_Logic.languageSetting.xml.defaultLanguage; } }
}
#endif

